#ifndef __CACHE_H__
#define __CACHE_H__

#include "common.h"

#define CACHE_BLOCK_SIZE 64
#define block_bits 6

#define CACHE_SIZE_L1 64 * 1024
#define l1_way 8
#define l1_sets_bits 7
#define l1_sets (1024 / 8)
#define l1_tag_bits 19


#define CACHE_SIZE_L2 4 * 1024 * 1024
#define l2_way 16
#define l2_sets 64*1024/16
#define l2_sets_bits 12
#define l2_tag_bits 14



typedef struct{
    bool valid;//有效位
    bool dirty;//脏位
    uint32_t tag;//标记位
    uint8_t block[CACHE_BLOCK_SIZE];
}block_;

block_ cache1[l1_sets][l1_way];
uint64_t l1_time;

block_ cache2[l2_sets][l2_way];
uint64_t l2_time;

void init_cache();
void p_cache_t();

int32_t l1_read(hwaddr_t addr);
void l1_write(hwaddr_t addr, size_t len, uint32_t data);

int32_t l2_read(hwaddr_t addr);
void l2_write(hwaddr_t addr, size_t len, uint32_t data);

void cache_ddr_read(hwaddr_t addr, void *data);
void cache_ddr_write(hwaddr_t addr, void *data, uint32_t* mask);

#endif // !__CACHE_H__